package com.hsh.servlet.user;/**
 * @author xrkhy
 * @date 2025/6/29 17:43
 * @description
 */

import com.hsh.service.UserService;
import com.hsh.service.impl.UserServiceImpl;
import com.hsh.utils.JsonResultUtil;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "UserDelete", value = "/UserDelete")
public class UserDelete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String param = request.getParameter("id");
        int id = Integer.parseInt(param);
        UserService service = new UserServiceImpl();
        int result = service.deleteUser(id);
        if (result > 0){
            response.getWriter().write(JsonResultUtil.buildResult(200, "删除成功", null));
        }else {
            response.getWriter().write(JsonResultUtil.buildResult(500, "删除失败", null));
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
